
<template>
    <div class="main_box" style="padding-right:10px">
        <div class="add_wrap">
            <div class="tit">
              <h2>编辑设备</h2>
              <el-button type="success" plain size="small" icon="fa fa-mail-forward" @click="returnList">返回</el-button>
            </div>
            <el-form :model="dataForm" ref="dataForm" label-width="200px" :rules="roleRules">
                <el-row>
                    <el-form-item label="设备名称" prop="equipName">
                        <el-input v-model="dataForm.equipName" clearable></el-input>
                    </el-form-item>
                    <el-form-item label="设备昵称" prop="equipNickName">
                        <el-input v-model="dataForm.equipNickName" clearable></el-input>
                    </el-form-item>
                    <el-form-item label="设备类型" prop="equipType">
                      <el-select   v-model="dataForm.equipType" clearable filterable>
                          <el-option v-for="item in equipTypeList" :key="item.id" :value="item.id" :label="item.name">
                          </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="MAC地址" prop="equipMac">
                        <el-input v-model="dataForm.equipMac" clearable :disabled="true"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                      <el-form-item>
                      <el-button plain type="primary" @click="sureClick">保 存</el-button>
                      <el-button plain @click="returnList">取 消</el-button>
                      </el-form-item>
                </el-row>
            </el-form>
        </div>
    </div>
  </template>

  <script>
  import * as message from "@/constants/message";
  import EquipOpenPoolApi from '@/api/equip/equipOpenPool';

  export default {
      name:"EquipAdd",
      data(){
          return{
              dataForm:{
                equipId:"",
                equipName:"",
                equipNickName:"",
                equipType:"",
                equipMac:"",
              },
              equipTypeList:[//设备类型列表
                  {id:3,name:"烟雾报警器"},
                  {id:4,name:"燃气报警器"},
                  {id:5,name:"门磁报警器"},
                  {id:6,name:"水浸卫士"},
                  {id:7,name:"摄像头"},
                  {id:8,name:"紧急报警器"},
                  {id:9,name:"跌倒报警器"},
                  {id:10,name:"红外探测器"},
              ],
              roleRules: {
                equipName:[
                    { required: true, message: "请输入设备名称", trigger: "blur" },
                ],
                equipType: [
                    { required: true, message: "请选择设备类型", trigger: "change" },
                ],
              },
          }
      },
      mounted(){
        this.init();
      },
      methods:{
        init(){
            this.dataForm.equipId = this.$route.query.id
            this.getData()
        },
        keydown(e) {
            if (e.keyCode == 32) {
                e.returnValue = false;
            }
        },
        getData(){
            var cond ={
                id: this.dataForm.equipId
            }
            EquipOpenPoolApi.getSafetyInfo(cond)
            .then(res =>{
                console.log(res)
                this.$Utils.bindingBean(this.dataForm, res.data)
                if(this.dataForm.equipType==99){
                    this.dataForm.equipType=""
                }
            })
        },
        sureClick(){
            // 提交
            this.$refs.dataForm.validate(valid =>{
            if(valid) {
                this.$confirm(message.MSG_CONFIRM_SAVE, message.TITLE_PROMPT, {})
                    .then(() => {
                        this.editData()
                    });
                }
            })
        },
        editData(){
            // 编辑
            var cond = {
                equipId:this.dataForm.equipId,
                equipName:this.dataForm.equipName,
                equipNickName:this.dataForm.equipNickName,
                equipType:this.dataForm.equipType,
                equipMac:this.dataForm.equipMac,
            }
            EquipOpenPoolApi.ActivateSafety(cond)
                .then(res =>{
                    this.$Utils.notifySuccess();
                    this.returnList();
                })
        },
        returnList(){
            // 返回上一界面
            this.$store.dispatch('delView', this.$route);
            this.$router.push({ path:'/equip/equipOpenPoolManagement'})
        }
      }
  }
  </script>

<style lang="scss" scoped>
@import "@/assets/css/views/add.scss";
</style>
  <style  lang="scss">


  </style>
